<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>作用域插槽1</title>
</head>

<body>
  <div id="root">
    <cpn>
      <!-- 2.5.x以下必须使用template模板，以上就不用template模板,使用其他模板也行，例如div -->
      <!-- 自动引用插槽对象 -->
      <template slot-scope="slot">
        <!-- .data就是传递过来的pLanguages -->
        <span v-for="item in slot.data">{{item}} - </span>
      </template>
    </cpn>

    <cpn>
      <div slot-scope="slot">
        <!-- <span v-for="item in slot.data">{{item}} * </span> -->
        <span>{{slot.data.join('%%')}}</span>
      </div>
    </cpn>
  </div>

  <template id="cpn">
    <div>
      <!-- 这里命名也可以起名为:abc,上面跟着修改就行 -->
      <slot :data="pLanguage">
        <ul>
          <li v-for="item in pLanguage">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>


  <script src="../js/vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#root',
      data: {
        message: 'Vue.js'
      },
      components: {
        cpn: {
          template: '#cpn',
          data() {
            return {
              pLanguage: ['java', 'python', 'javascript', 'c++', 'c#', 'go', 'swift']
            }
          },
          created() {
            // join() 数组转换为字符串，多个元素以-进行连接
            this.pLanguage.join('&&')
          }
        }
      }
    })
  </script>
</body>

</html>